package org.davidliebman.android.awesomecube;

import java.util.ArrayList;
import java.util.Random;

import android.util.Log;

public class ScrambleCube {
	
	private InputQueue<Integer> mList = new InputQueue<Integer>(); // output
	private ArrayList<Pair> mEnumerations = new ArrayList<Pair>(); // choose from here
	private String mString = new String(); // visual representation
	public final static int NUM_TURNS = 8; // num of turns for scramble
	
	public ScrambleCube () {
		add(new Pair("U", OrientationArray.MOVE_U_CW));
		add(new Pair("U'", OrientationArray.MOVE_U_CCW));
		add(new Pair("D", OrientationArray.MOVE_D_CW));
		add(new Pair("D'", OrientationArray.MOVE_D_CCW));
		add(new Pair("L", OrientationArray.MOVE_L_CW));
		add(new Pair("L'", OrientationArray.MOVE_L_CCW));
		add(new Pair("R", OrientationArray.MOVE_R_CW));
		add(new Pair("R'", OrientationArray.MOVE_R_CCW));
		add(new Pair("F", OrientationArray.MOVE_F_CW));
		add(new Pair("F'", OrientationArray.MOVE_F_CCW));
		add(new Pair("B", OrientationArray.MOVE_B_CW));
		add(new Pair("B'", OrientationArray.MOVE_B_CCW));
		
		mList = new InputQueue<Integer>();

	}
	
	public void add(Pair mP) {
		this.mEnumerations.add(mP);
	}
	
	public InputQueue<Integer> getQueue() {
		
		Random r = new Random(System.currentTimeMillis());
		mString = new String();
		mList = new InputQueue<Integer>();
		mList.clear();
		int mChoice = 0;
		for (int i = 0; i < NUM_TURNS; i ++) {
			mChoice =r.nextInt(this.mEnumerations.size() );
			mList.add(this.mEnumerations.get(mChoice).getEnum());
			mString = mString + this.mEnumerations.get(mChoice).getName();
			if (i != NUM_TURNS - 1) mString = mString + ", ";
		}
		return mList;
	}
	
	public String getString() {
		//note: you must call 'getQueue()' before 'getString()'
		return mString;
	}
}

class Pair {
	public String mName = new String();
	public Integer mEnum = new Integer(0);
	
	public Pair(String name, Integer num) {
		this.mName = name;
		this.mEnum = num;
	}

	public String getName() {
		return mName;
	}

	public void setName(String mName) {
		this.mName = mName;
	}

	public Integer getEnum() {
		return mEnum;
	}

	public void setEnum(Integer mEnum) {
		this.mEnum = mEnum;
	}
	
}